<template xmlns="" xmlns="" xmlns="">
  <div class="registerInfo-container">
    <modules-title title-name="盘点">
      <template slot="btn">
        <el-button class="border-btn" @click="exports">导出</el-button>
        <el-button class="border-btn" @click="back">返回</el-button>
      </template>
    </modules-title>
    <div class="main">
      <div class="table">
        <el-table
          :data="tableData"
          border
          :default-sort = "{prop: 'created_at', order: 'descending'}"
          :header-cell-style="{
            backgroundColor: '#F5F5F5',
            color: '#333333',
            fontFamily: 'MicrosoftYaHeiUI',
            fontSize: '14px',
            fontWeight: 900
          }"
        >
          <el-table-column label="盘点日期" sortable prop="created_at" align="center" >
            <template #default="{row}">
              {{row.created_at | dateFormat}}
            </template>
          </el-table-column>
          <el-table-column label="盘点药品" align="center" prop="product_name"></el-table-column>
          <el-table-column label="规格" align="center" prop="pack"></el-table-column>
          <el-table-column label="厂家" align="center" prop="production"></el-table-column>
          <el-table-column prop="batch_no" label="批号" v-if="state.drugs_management.function_set"
                           align="center"></el-table-column>
          <el-table-column label="库存" align="center">
            <template  #default="{row}">
              {{row.number}} {{row.piece_unit}}
            </template>
          </el-table-column>
          <el-table-column label="盘点库存" align="center" >
            <template  #default="{row}">
              {{row.check_number}} {{row.piece_unit}}
            </template>
          </el-table-column>
          <el-table-column label="盘点人" prop="real_name" align="center"></el-table-column>
        </el-table>
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pager.number"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="pager.size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
  import {getInventory,exportDiscDownload} from '@/api/drugsManagement';

  export default {
    name: "popWarehouse",
    data() {
      return {
        pager: {
          number: 1,
          size: 10
        },
        tableData: [],
        total: 0,
        state:{}
      };
    },
    created() {
      this.state = JSON.parse(this.$store.getters.systemSetting.dic_value)
      this.getInventoryData()
    },
    methods: {
      //获取数据
      getInventoryData() {
        let data={
          pager:this.pager
        }
        getInventory(data).then(res => {
          if (res.code === 200) {
            this.tableData = res.data.data || []
            this.total = res.data.total
          }
        })
      },
      //条数
      handleSizeChange(val) {
        this.pager.size = val
        this.getInventoryData()
      },
      //页码
      handleCurrentChange(val) {
        this.pager.number = val
        this.getInventoryData()
      },
      //返回
      back() {
        this.$router.go(-1)
      },
      async exports() {
        const res =await exportDiscDownload();
        const link = document.createElement("a");
        let blob = new Blob([res], {
          type:
            "application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
        });
        link.style.display = "none";
        link.href = URL.createObjectURL(blob);
        link.download = '盘点日志';
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
      },
      //
      toDetails(id) {
        this.$router.push({
          path:'/drugsManagement/Inventory/index/details',
          query:{id:id}
        })
      }
    }
  };
</script>
<style lang="scss" scoped>
  @import "@/assets/scss/drugsManagement/Inventory.scss";
</style>
